<?php
@session_start();
$loggedInUser = $_SESSION['userId'];
require_once 'forum.class.php';
require_once 'post.class.php';
$thread = new Forum();
$thread -> loadByThreadId($_REQUEST['post']);
$post = new Post();
//$threadIdSave=$post->getThreadId();
$showPost = $post -> load($_REQUEST['post']);
?>
<?php
if ($thread->getIsVisible()==1):
?>
<span class="type-heading" id="first-heading">Forum</span>
<span class="inside-level-1">> <?php echo $thread -> getThreadCategory();?></span>
<?php if ($thread->getUserId()==$loggedInUser):
$loggedInUser==$thread->getUserId()
?>
<form action="deleteThread.php" method="post">
	<input type="hidden" name="it_text_threadId" value="<?php echo $thread->getThreadId() ?>"/>
	<input type="submit" name="it_submit_delete" value="delete" />
</form>
<?php endif;?>
<table id="topic-content">
	<thead>
		<th class="first-column-long-topic"><?php echo $thread->getThreadSubject()
		?>
		<span id="total-post"> <?php
        $thread_id = $thread -> getThreadId();
        echo "(" . $thread -> totalPost($thread_id) . " Posts)";
			?></span></th>
		<th class="second-column"></th>
	</thead>
	<tbody>
		<tr>
			<td>started by <a class="username" href="#"> <?php
            $user_id = $thread -> getUserId();
            echo $thread -> getUsername($user_id);
            //echo 'require username here(php)'
			?></a> 5 hours ago </td>
		</tr>
		<?php
foreach ($showPost as $key):

if ($key->getIsVisible()==1):
$user_id_post=$key->getUserId();

		?>

		<tr>
			<td class="first-column-long-topic"><?php echo $key -> getPost();?></td>
			<td class="second-column">
			<img src="forum/images/profile.jpg" class="profile-photo-small" />
			<a href="#" class="username username-align"><?php echo $key->getUsername($user_id_post)
			?></a><span class="user-rank">Member</span></td>
			<?php if(($user_id_post==$loggedInUser || $loggedInUser==$thread->getUserId()) && ($thread->getIsVisible()==1)):
			?>
			<td>
			<form action="deletePost.php" method="post">
				<input type="hidden" name="it_text_PostId" value=<?php echo '"'.$key->getPostId().'"' ?>
				/>
				<input type="submit" name="it_submit_delete" value="delete" />
			</form></td>
		</tr>
		<?php endif;?>
		<?php

        endif;
        endforeach;
		?>
	</tbody>
</table>
<form action="post_reply.php" method="post">
	<input type="hidden" name="it_hidden_threadId" value="<?php echo $_REQUEST['thread'] ?>" />
	<textarea id="reply-textbox" name="it_textarea_replytextbox"></textarea>
	<input type="submit" id="reply-button"  value="Reply" name="it_submit_reply" />
</form>
<?php
else:
echo "The page you requested was not found.";endif;
?>
</div>
</body>
</html>
